package com.xiaomaoguai.jdk.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @Description :
 * @FileName: Read.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年6月26日 上午10:16:18
 * @Version:V1.00
 */
public class Read {

	public static void main(String[] args) {
		String read = "C:/Users/Administrator/Desktop/utils.js";
		String write = "C:/Users/Administrator/Desktop/utils_2.js";
		BufferedReader bReader = null;
		BufferedWriter bWriter = null;
		try {
			FileReader r = new FileReader(new File(read));
			FileWriter w = new FileWriter(new File(write));

			bReader = new BufferedReader(r);
			bWriter = new BufferedWriter(w);

			String line;

			int num = 0;

			while ((line = bReader.readLine()) != null) {
				bWriter.write(line);
				bWriter.newLine();
				bWriter.flush();
				num++;
			}
			System.out.println("num = " + num);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.out.println("文件找不到!");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("写文件出错!");
		} finally {

			try {
				if (bReader != null) {
					bReader.close();
				}
				if (bWriter != null) {
					bWriter.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
}
